// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueI18n from 'vue-i18n'
import store from './store'
import config from './config'

// Vue.prototype.$config = config
window.config = config

import { getLanguage, getUrlQuery } from '@/utils/function.js'

Vue.use(VueI18n)
const i18n = new VueI18n({
    locale: getLanguage(), // 语言标识
    // locale: getLanguage(getUrlQuery('language')), // 根据language参数切换语言包
    fallbackLocale: config.custom.language, // 默认语言
    messages: {
        'zh': require('./common/language/zh.json'), // 中文语言包
        'en': require('./common/language/en.json') // 英文语言包
    }
})

Vue.config.productionTip = false

// 路由全局钩子
router.beforeEach((to, from, next) => {
    // 根据language参数切换语言包
    i18n.locale = getLanguage(getUrlQuery('language'))
    // 继续下一步
    next()
})

/* eslint-disable no-new */
new Vue({
    el: '#app',
    store,
    router,
    i18n,
    template: '<App/>',
    components: { App }
})

